Ext.data.Types.BOOL.convert    = function(v){return (v === undefined || v === null || v === '') ? (this.useNull ? null : false) : (v === true || v === 'true' || v == 1);};
Ext.data.Types.BOOLEAN.convert = Ext.data.Types.BOOL.convert;  
Ext.data.Types.STRING.convert  = function(v){return (v === undefined || v === null) ? (this.useNull ? null : '') : String(v); };

var ActionRequest = Ext.data.Record.create([
    {name:'image',type:'auto'},
    {name:'user',type:'auto'},
    {name:'timestamp',type:'date'},
    {name:'actiongrant',type:'auto'},
    {name:'actionreject',type:'auto'},
    {name:'publication',type:'auto'},
    {name:'status',convert:function(v,rec){
        var _out;
        if (rec.actiongrant != null)
            _out = 1;
        if (rec.actionreject != null)
            _out = 2;
        if ((rec.actiongrant == null)&&(rec.actionreject == null))
            _out = 0;
        return _out;
    }
    }
]);

var ActionDownload = Ext.data.Record.create([
    {name:'id',type:'int'},
    {name:'image',type:'auto'},
    {name:'user',type:'auto'},
    {name:'timestamp',type:'date'},
    {name:'actiongrant',type:'auto'},
    {name:'actionunused',type:'auto'},
    {name:'actionused',type:'auto'},
    {name:'status',convert:function(v,rec){
        var _out;
        if (rec.actionused != null)
            _out = 1;
        if (rec.actionunused != null)
            _out = 2;
        if ((rec.actionused == null)&&(rec.actionunused == null))
            _out = 0;
        return _out;
    }}
]);

var ActionUsed = Ext.data.Record.create([
    {name:'image',type:'auto'},
    {name:'user',type:'auto'},
    {name:'timestamp',type:'date'},
    {name:'page',type:'int'},
    {name:'modified',type:'boolean'},
    {name:'publicationnumber',type:'auto'},
    {name:'actiondownload',type:'auto'}
]);

var Image = Ext.data.Record.create([
    {name:'id',type:'int'},
    {name:'lockedSearch',type:'boolean'},
    {name:'lockedDownload',type:'boolean'},
    {name:'name',type:'string'},
    {name:'timestamp',type:'date'},
    {name:'imagebackup',type:'auto'},
    {name:'imageprovider',type:'auto'},
    {name:'imagetype',type:'auto'},
    {name:'publicationnumber',type:'auto'},
    {name:'request',type:'auto'},
    {name:'requestType',convert:function(v,rec){
    	var _out = null;
    	if (rec.request != null)
            _out = rec.request.type ? 'Dibujo' : 'Foto';
        return _out;
    }}
]);

var ImageAlbum = Ext.data.Record.create([
    {name:'name',type:'string'}
]);

var ImageBackup = Ext.data.Record.create([
    {name:'id',type:'int'},
    {name:'name',type:'string',allowBlank:false}
]);

var ImageKeyword = Ext.data.Record.create([
    {name:'id',type:'int'},
    {name:'word',type:'string',allowBlank:false}
]);

var ImageProvider = Ext.data.Record.create([
    {name:'id',type:'int'},
    {name:'name',type:'string',allowBlank:false}
]);

var ImageType = Ext.data.Record.create([
    {name:'id',type:'int'},
    {name:'name',type:'string'}
]);

var Publication = Ext.data.Record.create([
    {name:'id',type:'int'},
    {name:'name',type:'string',allowBlank: false},
    {name:'publicationcountry',type:'auto'},
    {name:'publicationlevel',type:'auto'}
]);

var PublicationCountry = Ext.data.Record.create([
    {name:'id',type:'int'},
    {name:'message',type:'string',allowBlank:false}
]);

var PublicationLevel = Ext.data.Record.create([
    {name:'id',type:'int'},
    {name:'name',type:'string',allowBlank:false}
]);

var PublicationNumber = Ext.data.Record.create([
    {name:'id',type:'int'},
    {name:'number',type:'int',allowBlank:false},
    {name:'date',type:'date'},
    {name:'description',type:'string'},
    {name:'publication',type:'auto'}
]);

var UserGroup = Ext.data.Record.create([
    {name:'id',type:'int'},
    {name:'name',type:'string',allowBlank: false}
]);

var UserRole = Ext.data.Record.create([
    {name:'id',type:'int'},
    {name:'name',type:'string'},
    {name:'message',type:'string'}
]);

var User = Ext.data.Record.create([
    {name:'id',type:'int'},
    {name:'name',type:'string',allowBlank:false},
    {name:'firstName',type:'string'},
    {name:'lastName',type:'string'},
    {name:'email',type:'string'},
    {name:'fullName',convert:function(v,rec){
    	var _out = rec.name;
        if ((rec.firstName != null)||(rec.lastName != null)){
        	_out = (rec.firstName != null) ? rec.firstName : '';
        	if (_out.length > 0)
        	   _out += ' '; 
            _out += (rec.lastName != null) ? rec.lastName : ''; 
        }
        return _out;
    }}
]);

var Request = Ext.data.Record.create([
    {name:'id',type:'int'},
    {name:'number',type:'int',useNull:true},
    {name:'type',type:'boolean'},
    {name:'description',type:'string'},
    {name:'timestamp',type:'date'},
    {name:'pending',type:'boolean'},
    {name:'deliveryDate',type:'date'},
    {name:'environment',type:'string',useNull:true},
    {name:'objects',type:'string'},
    {name:'count',type:'int',useNull:true},
    {name:'backgroundColor',type:'string',useNull:true},
    {name:'storyboard',type:'string'},
    {name:'publication',type:'auto'},
    {name:'publicationnumber',type:'auto'},
    {name:'user',type:'auto'},
    {name:'orientation',type:'boolean',useNull:true}
]);

var RequestTake = Ext.data.Record.create([
    {name:'id',type:'int'},
    {name:'name',type:'string',allowBlank: false}
]);
    
var RequestAngle = Ext.data.Record.create([
    {name:'id',type:'int'},
    {name:'name',type:'string',allowBlank: false}
]);

var RequestUsage = Ext.data.Record.create([
    {name:'id',type:'int'},
    {name:'name',type:'string',allowBlank: false}
]);
var RequestModel = Ext.data.Record.create([
    {name:'id',type:'int'},
    {name:'gender',type:'boolean',allowBlank:false},
    {name:'ageMin',type:'int',allowBlank:false},
    {name:'ageMax',type:'int',allowBlank:false},
    {name:'count',type:'int',allowBlank:false},
    {name:'costume',type:'string',allowBlank:false},
    {name:'color',type:'string',allowBlank:false},
    {name:'others',type:'string'}    
]);

var RequestAttachment = Ext.data.Record.create([
    {name:'id',type:'int'},
    {name:'name',type:'string'},
    {name:'request',type:'auto'}
]);

var Model = Ext.data.Record.create([
    {name:'id',type:'int'},
    {name:'image',type:'auto'},
    {name:'school',type:'auto'},
    {name:'turn',type:'int'},
    {name:'gender',type:'boolean'},
    {name:'firstName',type:'string'},
    {name:'lastName',type:'string'},
    {name:'fullName', convert: function(v, rec) { return rec.firstName +' '+ rec.lastName }},
    {name:'birthDate',type:'date'},
    {name:'age',type:'string'}    
]);
var ModelRelationship = Ext.data.Record.create([
    {name:'id',type:'int'},
    {name:'name',type:'string',allowBlank: false}
]);
var ModelModel = Ext.data.Record.create([
    {name:'id',type:'int'},
    {name:'modelByIdModelA',type:'auto',allowBlank:false},
    {name:'modelByIdModelB',type:'auto',allowBlank:false},
    {name:'modelrelationship',type:'auto'}
]);
var ModelAddress = Ext.data.Record.create([
    {name:'id',type:'int'},
    {name:'street',type:'string',allowBlank: false},
    {name:'number',type:'int'},
    {name:'apartment',type:'string'}
]);
var ModelPhone = Ext.data.Record.create([
    {name:'id',type:'int'},
    {name:'number',type:'string',allowBlank: false}
]);
var ModelEmail = Ext.data.Record.create([
    {name:'id',type:'int'},
    {name:'email',type:'string',allowBlank: false}
]);
var ModelFeature = Ext.data.Record.create([
    {name:'id',type:'int'},
    {name:'feature',type:'string',allowBlank: false}
]);
var ModelNote = Ext.data.Record.create([
    {name:'id',type:'int'},
    {name:'text',type:'string',allowBlank: false}
]);
var ModelSchool = Ext.data.Record.create([
    {name:'id',type:'int'},
    {name:'name',type:'string',allowBlank: false}
]);
var ModelVisit = Ext.data.Record.create([
    {name:'id',type:'int'},
    {name:'delivered',type:'boolean',allowBlank:false},
    {name:'date',type:'date',allowBlank: false},
    {name:'request',type:'auto',allowBlank: false}
]);

/***************************************************************************/

/*var publication_responsible_current_store = new Ext.data.Store({
    storeId:'publication_responsible_current',
    url:'publication/get.json',
    baseParams:{responsible:true},
    sortInfo:{field:'name',direction:'ASC'},
    reader: new Ext.data.JsonReader(jsonReader_config,Publication),
    autoLoad:true
});

var publication_participant_current_store = new Ext.data.Store({
    storeId:'publication_participant_current',
    url:'publication/get.json',
    baseParams:{responsible:false},
    sortInfo:{field:'name',direction:'ASC'},
    reader: new Ext.data.JsonReader(jsonReader_config,Publication),
    autoLoad:true
});

var userrole_current_store = new Ext.data.Store({
    storeId:'userrole_current',
    url:'userrole/get.json',
    baseParams:{effective:true,idsUser:null},
    reader: new Ext.data.JsonReader(jsonReader_config,UserRole),
    autoLoad:false
});*/
    
var user_current_store = new Ext.data.Store({
    storeId:'user_current',
    url:'user/get.json',
    baseParams:{current:true},
    reader: new Ext.data.JsonReader(jsonReader_config,User),
    autoLoad:true/*,
    listeners:{
        load:function(this_,records,options){
            if (records.length === 1){
            	//userrole_current_store = Ext.StoreMgr.lookup('userrole_current');
                userrole_current_store.setBaseParam('idsUser',records[0].id);
                userrole_current_store.load();
                //publication_current_store = Ext.StoreMgr.lookup('publication_current');
                //Publicaciones en las que es responsable
                //publication_responsible_current_store.setBaseParam('idsUser',records[0].id);
                //publication_responsible_current_store.load();
                //Publicaciones en las que participa
                //publication_participant_current_store.setBaseParam('idsUser',records[0].id);
                //publication_participant_current_store.load();
            }
        }
    }*/
});